package br.com.tcc.core;

import java.awt.Component;
import java.util.List;

import br.com.tcc.helper.Caracteristica;
import br.com.tcc.helper.Player;
import br.com.tcc.helper.QuestionParser;
import br.com.tcc.screens.FormScreen;
import br.com.tcc.screens.GameScreen;
import br.com.tcc.screens.GraficoScreen;
import br.com.tcc.screens.SplashScreen;
import br.com.tcc.screens.TelaPontuacao;

public class Controller {

	PrincipalApplet applet;
	GameScreen game;
	FormScreen formScreen;
	SplashScreen splash;
	QuestionParser parser;
	Player player;

	public Controller(PrincipalApplet principalApplet) {
		this.applet = principalApplet;
		parser = new QuestionParser("questoes/questoes.xml");
		parser.realizaParse();
		player = new Player();
	}
	
	public void startSplash(){
		splash = new SplashScreen(this);
		applet.showScreen(splash);
	}
	
	public void startForm() {
		//applet.removeScreen(splash);
		//System.out.println("AQUI");
		formScreen = new FormScreen(parser.getCargosDisponiveis(), this, player);
		applet.showScreen(formScreen);
	}

	public void startGame() {
		applet.remove(formScreen);
		formScreen.stopAll();
		formScreen = null;
		
		System.out.println("\n ##### PARSER REALIZADO, PRINTANDO: ##### ");
		for (int i = 0; i < parser.getListaQuestaoPorCargo(1).size(); i++) {
			System.out.println(parser.getListaQuestaoPorCargo(1).get(i).getNumero()+" - "+parser.getListaQuestaoPorCargo(1).get(i).getEnunciado());
		}
		System.out.println("");
		
		game = new GameScreen(this, player, parser.getListaScores(), parser);
		applet.showScreen(game);
		game.start();
	}

	public void mostraGrafico(List<Caracteristica> caracteristica) {
		applet.removeScreen(game);
		game = null;
		GraficoScreen grafico = new GraficoScreen(this, caracteristica);
		applet.showScreen(grafico);
	}

	public void startTelaPontuacao(Component component) {
		if(component != null){
			applet.remove(component);
			component = null;
		}
		
		TelaPontuacao telaPontuacao = new TelaPontuacao(this, parser.getListaScores(), player);
		applet.showScreen(telaPontuacao);
		telaPontuacao.startAnimation();
	}

	public void mostraForm(Component component) {
		applet.removeScreen(component);
		component = null;
		
		formScreen = new FormScreen(parser.getCargosDisponiveis(), this, player);
		applet.showScreen(formScreen);
	}

	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	public void stop() {
		// TODO Auto-generated method stub
		
	}

}
